﻿<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001" %>
<%Session.CodePage=65001%>
<!--#include file="upload.inc"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body leftmargin="0" topmargin="0">
<% 
set upload=new upload_5xsoft       '建立上传对象
 '------------设置路径---------------------------- 
if upload.form("lj")="" then 
response.write( "上传目录出错!")
	set upload=nothing
	response.end
end if 

lj=upload.form("lj")
biao=upload.form("biao")

if right(lj,1)<>"/" then 
	lj=lj&"/" 
	end if	   

lj = Replace(lj,".","")
lj="../Pic/"
 '------------路径设置完----------------------------                                      
for each formname in upload.objFile   ''列出所有上传了的文件
set file=upload.file(formName)     ''生成一个文件对象

if file.FileSize=0 then         ''如果 FileSize = 0 说明没有文件数据
	response.write "请选择你要上传的文件![<a href=""javascript:history.back();"">重传</a>]"
	response.End
	set upload = Nothing
 end if

fileExt = formatFileName(file.FileName)

if Right(fileEXT,3)<>"gif" and Right(fileEXT,3)<>"jpg" and Right(fileEXT,3)<>"wmv" then'文件类型
		response.write "文件类别错误,只支持.jpg或.gif类型文件&[<a href=javascript:history.back();>重传</a>]"
		set upload=nothing
 		response.end
	End if
filename = lj&fomrmatTime&"."&formatFileName("."&fileExt)'取文件名
	filename2 = file.FileName
Dim filename3
filename3=fomrmatTime&"."&formatFileName("."&fileExt)
file.SaveAs Server.mappath(filename)   ''保存文件
set file=nothing
next

response.write "<script>parent.f2."&biao&".value ='"& filename3 &"'</script>"'把文件写入表单

set upload=nothing

  response.write "上传完毕!<a href="&filename&" target=_blank>查看</a>"
  response.end
  
  
'替换文件名中的非法字符
Function formatFileName(UpFileStr)
		dim tem
		tem = lcase(UpFileStr)
		tem = replace(replace(tem,"\",""),"/","")
		tem = replace(tem,"'","")
		tem = replace(tem," ","")
		tem = Replace(tem,Chr(0),"")
		tem = Replace(tem,".asp","")
		tem = Replace(tem,"asp","")
		tem = Replace(tem,"asa","")
		tem = Replace(tem,"aspx","")
		tem = Replace(tem,"cer","")
		tem = Replace(tem,"cdx","")
		tem = Replace(tem,"htr","")
		if Int(InStr(tem,"."))<1 then
			tem = "NotAllowFile"
		else
			tem = right(tem,len(tem)-InStr(tem,"."))
			if trim(tem) = "" then tem = "NotAllowFile" 
		end if
		formatFileName = tem
	End Function
	
'验证文件类型.返回True/False
Private Function CheckFileExt(AllowStr,FileExtStr)
		dim BoardUpload,i
		BoardUpload = AllowStr
		BoardUpload = Split(BoardUpload,",")
		CheckFileExt = False
		for i = 0 to UBound(BoardUpload)
			if lcase(FileExtStr) = lcase(Trim(BoardUpload(i))) Then
				CheckFileExt = True
				Exit Function
			end if
		next
	End Function
	
	'判断文件Content-Type,是否为应用程序文件
	Private Function NotFileType(FileType)
		NotFileType = False
		'response.write fileExt
		if left(cstr(lcase(trim(FileType))),12)="application/" Then
			if fileExt <> "rar" and fileExt <> "zip" then 
				NotFileType = True
				response.write fileExt
			end if
		end if
	End Function
	
	'格式化当前时间
	Function fomrmatTime()
		fomrmatTime = Year(now)&Month(now)&Day(now)&Hour(now)&Minute(now)&Second(now)
	End Function
%>

</body>
</html>
